<?php
require_once('service.php');
require_once('model/UserManager.php');
require_once('util/constants.php');
require_once('model/UserManager.php');
require_once('exceptions/UserDataException.php');        

class UserDataService extends Service {
	
	/* models */
	var $oUserManager;	// connection to user table
	
    public function UserDataService() {
        $this->oUserManager = new UserManager();
        
        parent::__construct('html/userData.html', true);
    }
    
	/**
	 * Authenticate user by username and password and then start a session
	 */
	public function checkmail() {
		try {			
			$mailbox = imap_open("{imap.gmail.com:993/imap/ssl}INBOX", "legendaryhorsed@gmail.com", "randale77#$!google");
			$checker = imap_check($mailbox);
        	$this->addToResponse($checker->Nmsgs, "iMails");
        	$this->addToResponse($checker->Recent, "iNewMails");
		} catch(Exception $ex) {			
            $this->error(imap_last_error());
		}
	}
    
    /**
     * 
     * Enter description here ...
     */
    public function get() {
        $this->addToResponse($this->oUserManager->getUserAsArray($this->sUserID, $this->sHash), "oUser");
    }
    
    /**
     * 
     * Enter description here ...
     */
    public function save() {        
        try {
        	$this->oUserManager->saveUser($this->sUserID, $this->sHash, $this->asParams);
        	$this->success();
        } catch(UserDataException $ude) {
            $this->error($ude->getMessage());
        }
    }
}

$oUserDataService = new UserDataService();
?>
